package com.jmyd.sharding.server.domain.vo;

import com.jmyd.sharding.server.domain.po.TUser;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author samphin
 * @date 2021/8/5 10:05
 */
@Data
public class UserVo implements Serializable {

    private Long id;

    /**
     * 名称
     */
    private String name;

    /**
     * 城市
     */
    private Integer cityId;

    /**
     * 性别
     */
    private Integer sex;

    /**
     * 电话
     */
    private String phone;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 创建时间
     */
    private Date createTime;

    public UserVo build(TUser po) {
        BeanUtils.copyProperties(po, this);
        this.setId(po.getId());
        return this;
    }

    public List<UserVo> build(List<TUser> poList) {
        if (CollectionUtils.isEmpty(poList)) {
            return new ArrayList<>(1);
        }
        return poList.stream().map(po -> new UserVo().build(po)).collect(Collectors.toList());
    }
}